home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / basic.arc / A2.TXT < prev    next >
Encoding:
Text File  |  1986-04-26  |  6.1 KB  |  149 lines

  1.  try to learn everything at once.  Take some time to
  2. play with what you've learned before beginning lesson two.
  3.  
  4.     If you are using the BASIC Prof,        |The PC-Prof.~
  5. let me know who you are!  Send your name        |P.O. Box 26~
  6. and address to:                        |Salina, Kansas~
  7.                             |67402-0026~
  8.  
  9.     If you like the Prof, include a contribution ($30 - $50 suggested) to
  10. help support development of additional volumes.  Please copy and share the
  11. Prof. with other IBM P.C. users.
  12. -----
  13. -----
  14. INPUT Statement
  15.  
  16.         The |INPUT~ statement allows you to input from the keyboard while the
  17. program is running.  When the computer comes to an INPUT statement, the program
  18. stops, displays a question mark, and waits until you enter a number, then it
  19. continues with the next line.  After the word INPUT you need to place a
  20. variable.
  21.  
  22.         example:  10 INPUT X
  23.  
  24.         You can place a |prompt~ (words, in quotes, to remind you what to
  25. enter) between the word INPUT and the variable.  If a semi-colon follows the
  26. prompt, then a question mark will be displayed after it.  If a comma follows
  27. the prompt, then no question mark will be displayed.
  28. -----
  29. INPUT Statement (continued)
  30.  
  31.         This is what an INPUT statement might look like in a program.
  32.  
  33.                 |10 INPUT "What is X equal to";X~
  34.                 |20 PRINT X;"+ 3 =";X+3~
  35.  
  36.         Try typing in this program, running it and watch what happens.  After
  37. you do that, change the semi-colon in line |10~ to a comma and |RUN~ it.  To
  38. execute the program again for a different variable value, type |RUN~ and put in a
  39. different number when the computer asks for X.
  40. -----
  41. String variables
  42.  
  43.         Variables can represent letters and text as well as numbers.  A
  44. variable representing a string of letters is called a |string variable~.
  45.  
  46.         String variables are written like |numeric~ variables with a trailing
  47. dollar sign.
  48.                 
  49.                 example: |XYZ$~="Greetings from sensible software!"
  50.  
  51.         You can input a string variable just like you did a numeric variable.
  52. Try running this sample program.
  53.  
  54.         |10 INPUT "What is your name";N$~
  55.         |20 PRINT "It's nice to meet you ";N$;", I'm the IBM Personal Computer."~
  56. -----
  57. More on the LET Statement
  58.  
  59.         Now that you can input and output from the computer, let's really make
  60. the computer do something.  Mathematical calculations can be performed in BASIC
  61. with the LET statement you were introduced to in lesson one.  The LET statement
  62. will set a variable equal to some numeric expression.  Here are the basic
  63. |arithmetic operators~ and how they are handled in BASIC.
  64.  
  65.               FORM              DESCRIPTION             EXAMPLES
  66.                 |+~               addition              A|+~B   6|+~12
  67.                 |-~               subtraction           A|-~B   23|-~7
  68.                 |*~               multiplication        A|*~B   3|*~(2-1)
  69.                 |/~               division              A|/~B   (8+2)|/~4
  70.                 |^~               exponentiation        A|^~B   (5*3)|^~2
  71. -----
  72. More on LET (continued)
  73.  
  74.         Here are two specific examples of the LET statement.
  75.  
  76.                 CELSIUS TO FAHRENHEIT CONVERSION
  77.  
  78.                         |10 LET F=1.8*C+32~
  79.  
  80.                 YEARLY INTEREST
  81.  
  82.                         |10 INTEREST=PRINCIPLE*RATE~
  83.  
  84.         Try writing a program that lets you input a Celsius temperature and
  85. have the computer convert it to Fahrenheit and PRINT the result.  (Use the
  86. |INPUT~, |LET~ and |PRINT~ statements.)  Remember, the IBM version of BASIC allows
  87. you to omit the word LET if you wish.
  88. -----
  89. More LET (continued)
  90.  
  91.         Here is one way to write the previous program.
  92.  
  93.                 |10 INPUT "Enter the Celsius temperature.",C~
  94.                 |20 F=1.8*C+32~
  95.                 |30 PRINT F;"Fahrenheit equals";C;"Celsius."~
  96. -----
  97. SAVE Command
  98.  
  99.         You can |SAVE~ a program on a diskette with the SAVE command.  This
  100. will save your program so that you can retrieve and run it again.  You must
  101. have a diskette ready for use to use this command (you can SAVE a few programs
  102. on the BASIC Prof diskette, but you should use a different diskette for large
  103. programs.)
  104.  
  105.         To SAVE a program, type |SAVE"name"~.  The |name~ can be anything you wish,
  106. but must be eight or less characters with no blank spaces.
  107.  
  108.         |Invalid characters are~
  109.  
  110.                         |+ = : ; , . ?~
  111.  
  112.         Type in the following program.  SAVE it with the name "INTEREST" by
  113. typing |SAVE"INTEREST"~.
  114.  
  115.         |10 INPUT "Enter the amount of principle.",PRIN~
  116.         |20 INPUT "What is the interest rate (use decimal)";RATE~
  117.         |30 INTEREST=PRIN*RATE~
  118.         |40 PRINT "$";INTEREST;"on $";PRIN;"at";RATE;"%"~
  119. ------
  120. LOAD Command
  121.  
  122.         The |LOAD~ command retrieves a program from the diskette and |loads~ it
  123. into the computer's memory.  Hopefully you were able to SAVE your program from
  124. the previous page.  The next time you want to use it, type |LOAD"name"~ (in
  125. this case |name~ is |INTEREST~).  Typing LIST will print the program on the screen.
  126.  
  127.         Try the |LOAD~ command now and |LIST~ the program.
  128. ------
  129. NEW Command
  130.  
  131.         The |NEW~ command |deletes~ the program that is currently in memory.
  132. It will also clears all variables.  When you want to begin writing a new
  133. program, you need to clear any old program remaining in the computer's memory.
  134. Otherwise, you may get lines from the old program mixed in with lines from the
  135. new program.
  136.  
  137.         The format for the NEW command is simply type NEW and press return.
  138. Try out the NEW command by typing |LOAD"INTEREST"~, press return and |LIST~
  139. the program.  Now type |NEW~ and press return and try to |LIST~ the program
  140. again.  This will |not~ erase the program from the |diskette~, |only~ from the
  141. computer's |memory~.
  142. -----
  143. End of Lesson Two
  144.  
  145.         One more lesson finished.  These first two lessons are the foundation
  146. for the rest that you will learn.  From this point on, programming really
  147. starts getting fun.  By the end of the next lesson you should be able to write
  148. your own simple games, but only if you understand everything covered so far.
  149. If you